package com.cloudptt.api.models.lbs;

import java.io.UnsupportedEncodingException;

public class ReportData
{
	private String mcpttId = null;
	private String funcNum = null;
	private LocationData locData = null;
	private String saInfo = null;

	public ReportData(String saInfo)
	{
		this.saInfo = saInfo;
	}

	public void setFuncNum(String funcNum) {
		this.funcNum = funcNum;
	}
	public void setSaInfo(String saInfo) {
		this.saInfo = saInfo;
	}
	public void setTriggerId(String triggerId)
	{
		this.mcpttId = triggerId;
	}

	public void setLocData(LocationData locData)
	{
		this.locData = locData;
	}
	public LocationData getLocData()
	{
		return locData;
	}
	public boolean isValid()
	{
		if(locData != null)
		{
			return locData.isValid();
		}
		return false;
	}

	public String toString(boolean isRequest,String requestMcpttId)
	{
		StringBuffer strBuff = new StringBuffer();
		strBuff.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>").append("\r\n");
		strBuff.append("<location-info xmlns=\"urn:3gpp:ns:mcpttLocationInfo:1.0\">").append("\r\n");
		if(requestMcpttId != null
			&& !requestMcpttId.equals(""))
		{
			strBuff.append("<Report ").append("ReportID = \"").append(requestMcpttId).append("\"");
		}
		else {
			strBuff.append("<Report ").append("ReportID = \"").append(mcpttId).append("\"");
		}
		strBuff.append(" ReportType=\"NonEmergency\">").append("\r\n");
		if(!isRequest) {
			strBuff.append("<TriggerId>").append(funcNum).append("</TriggerId>").append("\r\n");
		}
		strBuff.append("<CurrentLocation>").append("\r\n");
		strBuff.append("<CurrentServingEcgi type=\"Normal\">").append("\r\n");
		strBuff.append("<Ecgi>").append(saInfo).append("</Ecgi>").append("\r\n");
		strBuff.append("</CurrentServingEcgi>").append("\r\n");
		if(locData != null)
		{
			strBuff.append(locData.toString());
		}
		strBuff.append("<anyExt>").append("\r\n");

		strBuff.append("<CurrentServingNcgi type=\"Normal\">").append("\r\n");
		strBuff.append("<anyExt>").append("\r\n");
		strBuff.append("<Ncgi>").append(saInfo).append("</Ncgi>").append("\r\n");
		strBuff.append("</anyExt>").append("\r\n");
		strBuff.append("</CurrentServingNcgi>").append("\r\n");

		if(locData != null)
		{
			strBuff.append(locData.toString2());
		}

		strBuff.append("</anyExt>").append("\r\n");
		strBuff.append("</CurrentLocation>").append("\r\n");
//		strBuff.append("<ClientID>").append(clientId).append("</ClientID>").append("\r\n");

		strBuff.append("</Report>").append("\r\n");
		strBuff.append("</location-info>");

		try {
			return new String(strBuff.toString().getBytes(),"UTF-8");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return strBuff.toString();
	}
}
